const mysql = require('mysql2');
const mysqlConfig = require('../config').mysqlConfig;

const pool = mysql.createPool(mysqlConfig);
const promisePool = pool.promise();

module.exports = {
    execute: async function(sql, params = []) {
        try {
            const [rows] = await promisePool.query(sql, params);
            return rows;
        } catch (error) {
            console.error(sql, params);
            throw(error);
        }
    }
}